var app = getApp(),
    Data = require("../../utils/util.js");
var e = require("../../config/config");
Page({
   data: {

    },
    onLoad: function(t) {
        var e = this;
        wx.getLocation({
            type: "wgs84",
            success: function(t) {
                t.latitude, t.longitude, t.speed, t.accuracy
            }
        }), wx.getSystemInfo({
            success: function(t) {
                e.setData({
                    windowHeight: t.windowHeight
                }), console.log(t)
            }
        }), app.util.request({
            url: "entry/wxapp/Url2",
            cachetime: "0",
            success: function(t) {
                wx.setStorageSync("url2", t.data)
            }
        }), app.util.request({
            url: "entry/wxapp/Url",
            cachetime: "0",
            success: function(t) {
                console.log(t), wx.setStorageSync("url", t.data), e.setData({
                    url: t.data
                })
            }
        }), e.reload()
    },
    reload: function(t) {
		var e = this;
        wx.login({
            success: function(t) {
                var e = t.code;
                wx.setStorageSync("code", e), wx.getUserInfo({
                    success: function(t) {
                        console.log(t), wx.setStorageSync("user_info", t.userInfo);
                        var a = t.userInfo.nickName,
                            n = t.userInfo.avatarUrl;
                        app.util.request({
                            url: "entry/wxapp/openid",
                            cachetime: "0",
                            data: {
                                code: e
                            },
                            success: function(t) {
                                console.log(t), wx.setStorageSync("key", t.data.session_key), wx.setStorageSync("openid", t.data.openid);
                                var e = t.data.openid;
                                app.util.request({
                                    url: "entry/wxapp/Login",
                                    cachetime: "0",
                                    data: {
                                        openid: e,
                                        img: n,
                                        name: a
                                    },
                                    success: function(t) {
                                        console.log(t), wx.setStorageSync("users", t.data), wx.setStorageSync("uniacid", t.data.uniacid)
                                    }
                                })
                            }
                        })
                    },
                    fail: function(t) {
                        wx.getSetting({
                            success: function(t) {
                                0 == t.authSetting["scope.userInfo"] && wx.openSetting({
                                    success: function(t) {}
                                })
                            }
                        })
                    }
                })
            }
        });
		wx.getLocation({
            type: "wgs84",
            success: function(t) {
                wx.setStorageSync("Location", t);
                var a = t.latitude + "," + t.longitude;
                app.util.request({
                    url: "entry/wxapp/map",
                    cachetime: "0",
                    data: {
                        op: a
                    },
                    success: function(t) {
                        console.log(t), e.setData({
                            dwcity: t.data.result.address_component.city
                        }), app.util.request({
                            url: "entry/wxapp/System",
                            cachetime: "0",
                            success: function(t) {
                                console.log(t);
                                var a = t.data.gd_key;
                                "" == a && wx.showModal({
                                    title: "配置提示",
                                    content: "请在后台配置高德地图的key",
                                    showCancel: !0,
                                    cancelText: "取消",
                                    confirmText: "确定",
                                    success: function(t) {},
                                    fail: function(t) {},
                                    complete: function(t) {}
                                }), new(require("../amap-wx.js").AMapWX)({
                                    key: a
                                }).getWeather({
                                    success: function(t) {
                                        var a, n, i = t.liveData.city,
                                            o = t.liveData.weather,
                                            s = t.liveData.reporttime.slice(0, 10),
                                            c = (0 == (a = new Date(s)).getDay() && (n = "星期日"), 1 == a.getDay() && (n = "星期一"), 2 == a.getDay() && (n = "星期二"), 3 == a.getDay() && (n = "星期三"), 4 == a.getDay() && (n = "星期四"), 5 == a.getDay() && (n = "星期五"), 6 == a.getDay() && (n = "星期六"), n),
                                            r = t.temperature.data;
                                        e.setData({
                                            area: i,
                                            reporttime: s,
                                            weather: o,
                                            w1: c,
                                            temperature: r
                                        })
                                    },
                                    fail: function(t) {}
                                });
                                var n = ["最新信息"];
                                "1" == t.data.is_sjrz && n.push("热门商家"), "1" == t.data.is_pageopen && n.push("黄页114"), "1" == t.data.is_pcfw && n.push("顺风车"), console.log(n), wx.setStorageSync("System", t.data), 1 == t.data.many_city ? (wx.setStorageSync("city", t.data.cityname), e.setData({
                                    city: t.data.cityname
                                })) : (console.log(wx.getStorageSync("city_type")), 1 != wx.getStorageSync("city_type") ? (wx.setStorageSync("city", e.data.dwcity), e.setData({
                                    city: e.data.dwcity
                                })) : (e.setData({
                                    city: wx.getStorageSync("city")
                                }), console.log("choosecity")));
                                var i = wx.getStorageSync("city");
                                console.log(i), app.util.request({
                                    url: "entry/wxapp/SaveHotCity",
                                    cachetime: "0",
                                    data: {
                                        cityname: i,
                                        user_id: wx.getStorageSync("users").id
                                    },
                                    success: function(t) {
                                        console.log(t)
                                    }
                                }), wx.setNavigationBarTitle({
                                    title: t.data.pt_name
                                }), wx.setStorageSync("color", t.data.color), wx.setNavigationBarColor({
                                    frontColor: "#ffffff",
                                    backgroundColor: wx.getStorageSync("color"),
                                    animation: {
                                        duration: 0,
                                        timingFunc: "easeIn"
                                    }
                                });
                                i = wx.getStorageSync("city");
                                e.setData({
                                    System: t.data,
                                    bkarr: n
                                });
                            }
                        })
                    }
                })
            },
            fail: function(t) {
                wx.getSetting({
                    success: function(t) {
                        0 == t.authSetting["scope.userLocation"] && wx.openSetting({
                            success: function(t) {}
                        })
                    }
                })
            }
        });
		app.util.request({
            url: "entry/wxapp/Views",
            cachetime: "0",
            success: function(t) {
                console.log(t);
                var a = t.data;
                "" == a ? a = 0 : Number(a) > 1e4 && (a = (Number(a) / 1e4).toFixed(2) + "万"), e.setData({
                    views: a
                })
            }
        });
		app.util.request({
            url: "entry/wxapp/Num",
            cachetime: "0",
            success: function(t) {
                e.setData({
                    Num: t.data
                })
            }
        })
    },


    onShow: function() {},
    onHide: function() {},
    onUnload: function() {
        
    },
    onPullDownRefresh: function() {

    },
	navToDetail: function() {

        wx.navigateTo({
            url: e.ROUTE.MAP
        });
    },
    onShareAppMessage: function() {}
});